package com.bread.testinterface3.Controller;


import com.bread.bapiclientstater.model.User;
import com.bread.bapiclientstater.utils.SignUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/*
*查询名称API
*
*
  */
@RestController
@RequestMapping("/name")
public class NameController {

    @GetMapping("/getuser")
    public String getNameByGet(String name, HttpServletRequest request){
//        String accessKey = request.getHeader("accessKey");
//        String secretKey = request.getHeader("secretKey");
//        if(!accessKey.equals("bread")||!secretKey.equals("yupi")){
//            throw new RuntimeException("密钥错误");
//        }
        return "get name is  "+name;
    }

    @PostMapping("/postuser")
    public String getNameByPost(@RequestParam String name){
        return "post name is  "+name;
    }

    @PostMapping("/restuser")
    public String getUsernameByPost(@RequestBody User user, HttpServletRequest request){
//        String accessKey = request.getHeader("accessKey");
//        String nonce = request.getHeader("nonce");
//        String timestamp = request.getHeader("timestamp");
//        String sign = request.getHeader("sign");
//        String body = request.getHeader("body");
//        if(!accessKey.equals("bread")){
//            throw new RuntimeException("无权限");
//        }
//        String serviceSign = SignUtils.genSign(body, "yupi");
//        if(!sign.equals(serviceSign)){
//            throw new RuntimeException("无权限");
//        }
//

        String result= "restpost name is  "+user.getUsername();
        //调用成功后添加调用次数
        return result;
    }

}
